﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NancyOauth2.Models;

namespace NancyOauth2.Domains
{
    public class ApplicationDomain:IApplicationDomain
    {
        static ApplicationDomain()
        {
            
        }

        private  static readonly List<ApplicationModel>  _applicationModels = new List<ApplicationModel>()
        {
            new ApplicationModel()
            {
                ClientId = "cox",
                ClientSecret = "cox",
                RedirectUri = "www.baidu.com",
                Guid = Guid.NewGuid()
            },
            new ApplicationModel()
            {
                ClientId = "rwecho",
                ClientSecret = "rwecho",
                RedirectUri = "www.baidu.com",
                Guid = Guid.NewGuid()
            },
            new ApplicationModel()
            {
                ClientId = "syd",
                ClientSecret = "syd",
                RedirectUri = "www.baidu.com",
                Guid = Guid.NewGuid()
            },
             new ApplicationModel()
            {
                ClientId = "yb",
                ClientSecret = "yb",
                RedirectUri = "www.baidu.com",
                Guid = Guid.NewGuid()
            }
        };

        public IEnumerable<ApplicationModel> GetValidApps()
        {
            //yield return new ApplicationModel()
            //{
            //    ClientId = "cox",
            //    ClientSecret = "cox",
            //    RedirectUri = "www.baidu.com",
            //    Guid = Guid.NewGuid()
            //};

            //yield return new ApplicationModel()
            //{
            //    ClientId = "rwecho",
            //    ClientSecret = "rwecho",
            //    RedirectUri = "www.baidu.com",
            //    Guid = Guid.NewGuid()
            //};
            //yield return new ApplicationModel()
            //{
            //    ClientId = "syd",
            //    ClientSecret = "syd",
            //    RedirectUri = "www.baidu.com",
            //    Guid = Guid.NewGuid()
            //};
            //yield return new ApplicationModel()
            //{
            //    ClientId = "yb",
            //    ClientSecret = "yb",
            //    RedirectUri = "www.baidu.com",
            //    Guid = Guid.NewGuid()
            //};
            return _applicationModels;
        }

        public IEnumerable<Tuple<string, string, Guid>> GetUsers()
        {
            return GetValidApps().Select(o=> new Tuple<string, string, Guid>(o.ClientId,o.ClientSecret,o.Guid));
        }
    }

    public interface IApplicationDomain
    {
        IEnumerable<ApplicationModel> GetValidApps();
        IEnumerable<Tuple<string, string, Guid>> GetUsers();
    }
}